//go:generate goxgen .

package main

import (
	"database/sql"
	"fmt"
	"github.com/yourusername/gox/pkg/runtime"
)

func GetUsersByStatus(db *sql.DB, status string) {
	// 基础Query语法
	query1 := func() *runtime.Query {
		__gox_sql_2_builder := runtime.NewQueryBuilder()
		__gox_sql_2_builder.AddText("SELECT * FROM users WHERE status = ")
		__gox_sql_2_builder.AddParam(status)
		__gox_sql_2 := __gox_sql_2_builder.Build()
		return __gox_sql_2
	}()
	fmt.Println("Query 1:", query1.String())

	// 带文本插入的Query
	tableName := "users"
	query2 := func() *runtime.Query {
		__gox_sql_1_builder := runtime.NewQueryBuilder()
		__gox_sql_1_builder.AddText("SELECT count(*) FROM ")
		__gox_sql_1_builder.AddText(fmt.Sprintf("%v", tableName))
		__gox_sql_1 := __gox_sql_1_builder.Build()
		return __gox_sql_1
	}()
	fmt.Println("Query 2:", query2.String())

	// 条件逻辑
	includeDeleted := false
	query3 := func() *runtime.Query {
		__gox_sql_0_builder := runtime.NewQueryBuilder()
		__gox_sql_0_builder.AddText(" SELECT * FROM users WHERE ")
		if __result := func() (__result interface{}) {
			if includeDeleted {
				return "1=1"
			} else {
				return "deleted_at IS NULL"
			}
			return __result
		}(); __result != nil {
			__gox_sql_0_builder.AddText(fmt.Sprintf("%v", __result))
		}
		__gox_sql_0 := __gox_sql_0_builder.Build()
		return __gox_sql_0
	}()
	fmt.Println("Query 3:", query3.String())
}

func main() {
	fmt.Println("新的Query()语法示例")
	GetUsersByStatus(nil, "active")
}
